# middleware.py
import logging

async def log_requests_middleware(request, call_next):
    """
    日志中间件：记录请求的接口名称
    """
    # 获取请求的路由路径
    endpoint = request.url.path

    # 将接口名称添加到日志记录中
    logger = logging.getLogger()
    logger.info(
        f"Request received for endpoint: {endpoint}",
        extra={"endpoint": endpoint}
    )

    # 继续处理请求
    response = await call_next(request)
    return response